package org.example.service.impl;

import org.example.mapper.DeptMapper;
import org.example.pojo.Dept;
import org.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public boolean deleteById(Integer id) {
        Integer num = deptMapper.getempBydeptid(id);
        if(num==0){
            deptMapper.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public void add(Dept dept) {
//        补全基础属性 - createTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

//        调用Mapper接口方法插入数据
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
//        补全基础属性 - createTime
        dept.setUpdateTime(LocalDateTime.now());

//        调用Mapper接口方法更新数据
        deptMapper.update(dept);
    }

}
